/*************************************************************************
    > File Name: graph.h
    > Author: liujing
    > Mail: jingliu.cs@gmail.com 
    > Created Time: 2014年10月20日 星期一 20时49分11秒
 ************************************************************************/

#ifndef _MY_NFA_
#define _MY_NFA_

#include <vector>
#include <string>
using namespace std;

//the basic node in nfa graph
class GraphNode{
public:
	GraphNode(void);
	~GraphNode(void);
public:
	static int id;
	int ID;	//the unique id of one node
	static void resetID();
	int getID();
};

//the edge between two node in dfa graph
//the info of edge contains the end node and the transitive character
class EdgeLink{
public:
	EdgeLink(void);
	~EdgeLink(void);
public:
	EdgeLink(GraphNode* graphNode, wchar_t str);
	EdgeLink::EdgeLink(GraphNode* graphNode, wchar_t str,bool backEdge);
	GraphNode* graphNode;
	//string str;
	wchar_t str;
	bool backEdge;
};

//the adjacency list of node in nfa graph
class GraphLine{
public:
	GraphLine(void);
	~GraphLine(void);
public:	
	GraphLine(GraphNode* graphNode);
	GraphNode* graphNode;
	vector<EdgeLink*> graphNodes;
};

//nfa is diagraph, hence use adjacency list to represent diagraph
class Graph{
public:
	Graph(void);
	~Graph(void);
public:
	Graph(int n);	//n is the sum of nodes;
	void addEdge(GraphNode n1,GraphNode n2,wchar_t str);
	void addBackEdge(GraphNode n1, GraphNode n2, wchar_t str);
	vector<GraphLine*> graphLines;
	int start,end;	//the index of start node and end node
};

#endif
